package cn.lds.j375.chlm.exception;

import cn.lds.j375.chlm.dto.ResultEnum;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class ChlmExceptionResolve implements HandlerExceptionResolver {
    @Override
    public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {

        ChlmException chlmException = null;

        if (ex instanceof ChlmException){
            chlmException = (ChlmException) ex;
        }else{
            //输出异常
            ex.printStackTrace();
            chlmException = new ChlmException(ResultEnum.ERROR.getMsg());
        }

        ModelAndView mv = new ModelAndView();

        mv.addObject("ex",chlmException);

        mv.setViewName("error");

        return mv;
    }
}
